<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: new_products.php 135 2013-09-22 07:30:55Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 135 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:30:55 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$module_smarty = new Smarty();
$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');

$fsk_lock = '';
if ($_SESSION['customers_status']['customers_fsk18_display'] == '0')
	$fsk_lock = ' and p.products_fsk18!=1';

if (GROUP_CHECK == 'true')
	$group_check = " and p.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 ";

if ((!isset ($new_products_category_id)) || ($new_products_category_id == '0')) {
	$site = 'new_products_default';
	$title = NEW_PRODUCTS_DEFAULT;

	$new_products_query = "SELECT
								p.products_fsk18,
								p.products_shippingtime,
								p.products_model,
								p.products_ean,
								p.products_isbn,
								p.products_list_overlay,
								p.products_price,
								p.products_quantity,
								p.products_image,
								p.products_weight,
								p.products_id,
								p.brand_id,
								p.products_price,
								p.products_vpe,
								p.products_vpe_status,
								p.products_vpe_value,
								p.products_discount_allowed,
								p.products_tax_class_id,
								pd.products_name,
								pd.products_short_description,
								pd.products_description,
								pd.products_img_alt
							FROM
								".TABLE_PRODUCTS." p
								LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." AS pd
									ON (pd.language_id = '".(int) $_SESSION['languages_id']."' AND pd.products_id = p.products_id)
							WHERE
								p.products_startpage = '1'
								".$group_check.$fsk_lock.$filter_products."
							AND
								p.products_status = '1'
							ORDER BY
								p.products_startpage_sort ASC";
} else {
	$site = 'new_products';
	$title = NEW_PRODUCTS;

	if (MAX_DISPLAY_NEW_PRODUCTS_DAYS != '0') {
		$date_new_products = date("Y.m.d", mktime(1, 1, 1, date(m), date(d) - MAX_DISPLAY_NEW_PRODUCTS_DAYS, date(Y)));
		$days = " AND p.products_date_added > '".$date_new_products."' ";
	}
	$new_products_query = "SELECT
								p.products_fsk18,
								p.products_shippingtime,
								p.products_model,
								p.products_ean,
								p.products_isbn,
								p.products_list_overlay,
								p.products_price,
								p.products_quantity,
								p.products_image,
								p.products_weight,
								p.products_id,
								p.brand_id,
								p.products_price,
								p.products_vpe,
								p.products_vpe_status,
								p.products_vpe_value,
								p.products_discount_allowed,
								p.products_tax_class_id,
								pd.products_name,
								pd.products_short_description,
								pd.products_description,
								pd.products_img_alt
							FROM
								".TABLE_PRODUCTS." p,
								".TABLE_PRODUCTS_DESCRIPTION." pd,
								".TABLE_PRODUCTS_TO_CATEGORIES." p2c,
								".TABLE_CATEGORIES." c
							WHERE
								c.categories_status='1'
							AND
								p.products_id = p2c.products_id
							AND
								p.products_id=pd.products_id
							AND
								p2c.categories_id = c.categories_id
								".$group_check.$days.$fsk_lock.$filter_products."
							AND
								c.parent_id = '".$new_products_category_id."'
							AND
								p.products_status = '1'
							AND
								pd.language_id = '".(int) $_SESSION['languages_id']."'
							ORDER BY
								p.products_date_added DESC";
}
$row = 0;
$module_content = array ();
$new_products = $db->db_query_limit($new_products_query, MAX_DISPLAY_NEW_PRODUCTS, true);
$list_data = get_list_data($site);
while(!$new_products->EOF) { $row++;
	$module_content[] = $product->buildDataArray($new_products->fields,'thumbnail', $list_data, $row);
	$new_products->MoveNext();
}

if (sizeof($module_content) >= 1) {
	$module_smarty->assign('language', $_SESSION['language']);
	$module_smarty->assign('module_content', $module_content);
	$module_smarty->assign('TITLE', $title);
	if($list_data['col']>1)
		$module_smarty->assign('CLASS_NAME', 'grid');
	else
		$module_smarty->assign('CLASS_NAME', 'list');
	$module_smarty->assign('LIST_NAME', $site);

	 if (!CacheCheck()) {
		$module_smarty->caching = false;
		$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/'.$list_data['list_file'].'.html');

	} else {
		$module_smarty->caching = true;
		$module_smarty->cache_lifetime = CACHE_LIFETIME;
		$module_smarty->cache_modified_check = CACHE_CHECK;
		$cache_id = $new_products_category_id.$_SESSION['language'].$_SESSION['customers_status']['customers_status_name'].$_SESSION['currency'];
		$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/'.$list_data['list_file'].'.html', $cache_id);

	}
	$default_smarty->assign('MODULE_new_products', $module);
}